package webdev.dto;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;

public class Places implements Parcelable {

	private String id;
	private String title;
	private String description;
	private String address;
	private String phoneNumber;
	private String imageName;
	private String lat;
	private String lng;
	
	public Places() {}
	
	public Places(Parcel in) {
		setId(in.readString());
		setTitle(in.readString());
		setDescription(in.readString());
		setAddress(in.readString());
		setPhoneNumber(in.readString());
		setImageName(in.readString());
		setLat(in.readString());
		setLng(in.readString());
	}
	
	@Override
	public int describeContents() {
		return 0;
	}
	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(getId());
		dest.writeString(getTitle());
		dest.writeString(getDescription());
		dest.writeString(getAddress());
		dest.writeString(getPhoneNumber());
		dest.writeString(getImageName());
		dest.writeString(getLat());
		dest.writeString(getLng());
	}
	
	public static final Parcelable.Creator<Places> CREATOR = new Creator<Places>() {

		@Override
		public Places createFromParcel(Parcel source) {
			return new Places(source);
		}

		@Override
		public Places[] newArray(int size) {
			return new Places[size];
		}
		
	};
	
	/**
	 * Parser data
	 * @return
	 */
	public void parser(JSONObject mJsonObject) {
		if(mJsonObject == null) {
			return;
		}
		
		// Id
		if(!mJsonObject.isNull("id")) {
			try {
				id = mJsonObject.getString("id");
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		
		// title
		if(!mJsonObject.isNull("title")) {
			try {
				title = mJsonObject.getString("title");
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		
		// description
		if(!mJsonObject.isNull("description")) {
			try {
				description = mJsonObject.getString("description");
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		
		// address
		if(!mJsonObject.isNull("address")) {
			try {
				address = mJsonObject.getString("address");
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		
		// phonenumber
		if(!mJsonObject.isNull("phoneNumber")) {
			try {
				phoneNumber = mJsonObject.getString("phoneNumber");
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		
		// imageName
		if(!mJsonObject.isNull("imageName")) {
			try {
				imageName = mJsonObject.getString("imageName");
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		
		// lat
		if(!mJsonObject.isNull("lat")) {
			try {
				lat = mJsonObject.getString("lat");
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		
		// lng
		if(!mJsonObject.isNull("lng")) {
			try {
				lng = mJsonObject.getString("lng");
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
	}
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getPhoneNumber() {
		return phoneNumber;
	}
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	public String getImageName() {
		return imageName;
	}
	public void setImageName(String imageName) {
		this.imageName = imageName;
	}
	public String getLat() {
		return lat;
	}
	public void setLat(String lat) {
		this.lat = lat;
	}
	public String getLng() {
		return lng;
	}
	public void setLng(String lng) {
		this.lng = lng;
	}
	
}
